//
//  TSAutoHeightTableViewCell.swift
//  TSProfitProject
//
//  Created by TMS on 2019/11/4.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

class TSAutoHeightTableViewCell: UITableViewCell {
    
    var label : UILabel!

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        configViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    public func setupLabel(content:String, topInset:CGFloat, textColor:String, fontSize:CGFloat) {

        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 10
        
        let attribute = NSMutableAttributedString.init(string: content)
        attribute.addAttributes([NSAttributedString.Key.foregroundColor: UIColor.hexadecimalColor(hexadecimal: textColor), NSAttributedString.Key.font:UIFont.systemFont(ofSize: fontSize, weight: .medium), NSAttributedString.Key.paragraphStyle:paragraphStyle], range: NSMakeRange(0, content.count))
        
        label.attributedText = attribute
        label.snp.updateConstraints { (make) in
            make.top.equalTo(topInset)
        }
    }
    
    func configViews() {
        label = UILabel.init()
        label.numberOfLines = 0
        self.contentView.addSubview(label)
        label.snp.makeConstraints { (make) in
            make.left.equalTo(12)
            make.width.equalTo(SCREEN_WIDTH - 2*12)
            make.top.equalTo(0.001)
            
            make.bottom.equalTo(-10)
//            make.bottom.equalToSuperview().offset(-10)
        }
    }

}
